package com.rui.lost.controller;


import com.rui.common.vo.Result;
import com.rui.lost.entity.Lost;
import com.rui.lost.service.LostService;
import com.rui.lost.vo.LostQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/lost")
public class LostController {
@Autowired
    private LostService lostService;

    @GetMapping("")
    public  String toLostListUI(){
        return "lost/lostList";
    }
    @GetMapping("/list")//查询数据时，使用get请求
    @ResponseBody         //将方法返回为json数据
    public Result<Object> getLostList(LostQuery param){
        List<Lost> list = lostService.getLostList(param);//查出员工信息
        Long count = lostService.countLostList(param);   //分页
        return Result.success(list, count);
    }
    @PostMapping("")//新增数据时，用post请求
    @ResponseBody //将方法返回为json数据
    public Result<Object> addLost(Lost lost){
        lostService.addLost(lost);
        return Result.success("添加物品成功！");
    }
    @GetMapping("/add/ui")
    public String toAddUI(){
        return "lost/addLost";
    }

    @DeleteMapping("/{los}") //用于处理http中的delete请求，并将请求映射到删除方法中
    @ResponseBody               //将方法中的参数绑定到请求URI中的模板变量上
    public Result<Object> deleteLostBylos(@PathVariable("los") String los){
        lostService.deleteLostBylos(los);
        return Result.success("删除信息成功");
    }
    @GetMapping("/{ids}")
    public String getLostByids(@PathVariable("ids") Integer ids,Model model){
        Lost lost =  lostService.getLostByids(ids);
        model.addAttribute("lost",lost);
        return "lost/lostEdit";
    }
    @PutMapping("")
    @ResponseBody
    public Result<Object> updateLost(Lost lost ){
        lostService.updateLost(lost);
        return  Result.success("修改成功");
    }
}
